﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CTkitMvvmDemo
{
    public class MessagerBase
    {

        static void Test()
        {
            var vm = new ViewModel();
            //WeakReferenceMessenger.Default.Send(vm);
            vm.Number = 1;
        }
    }

    partial class ViewModel : ObservableObject
    {

        public ViewModel()
        {
            WeakReferenceMessenger.Default.Register<ValueChangedMessage<string>>(this, Receiver);
        }

        void Receiver(object recipient, ValueChangedMessage<string> message)
        {
            Console.WriteLine(message.Value);
        }

         

        private int _number;
        public int Number
        {
            get => _number;
            set  {
                if (SetProperty(ref _number, value))
                {
                    WeakReferenceMessenger.Default.Send(new PropertyChangedMessage<int>(this, nameof(Number), default, value));
                }
            } 
        }

       
    }



}
